package com.hc.music.controller;

import com.hc.music.common.R;
import com.hc.music.entity.Song;
import com.hc.music.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("song")
public class SongController {
    @Autowired
    SongService songService;

    @PostMapping(value = "insert")
    public R insert(Song song , @RequestParam("lrcFile") MultipartFile lrcFile , @RequestParam("file") MultipartFile file){
        return songService.insert(song, lrcFile, file);
    }

    @RequestMapping("selectBySingerId")
    public R selectBySingerId(@RequestParam Integer singerId){
        return songService.selectBySingerId(singerId);
    }

    @RequestMapping("update")
    public R update(@RequestBody Song song){
        return songService.update(song);
    }

    @RequestMapping("delete")
    public R delete(@RequestParam Integer id){
        return songService.delete(id);
    }

    @RequestMapping(value = "updatePic",method = RequestMethod.POST)
    public R updatePic(@RequestParam("file") MultipartFile file,@RequestParam("id") Integer id){
        return songService.updateImage(file,id);
    }

    @PostMapping("updateUrl")
    public R updateUrl(@RequestParam("id") Integer id,@RequestParam("file") MultipartFile file){
        return songService.updateUrl(file,id);
    }

    @PostMapping("updateLrc")
    public R updateLrc(@RequestParam("file")MultipartFile file,@RequestParam("id") Integer id){
        return songService.updateLrc(file,id);
    }

    @RequestMapping("selectByLikeName")
    public R selectByLikeName(@RequestParam String name){
        return songService.selectBySingerName(name);
    }

    @RequestMapping("selectById")
    public R selectById(@RequestParam Integer id){
        return songService.selectById(id);
    }

    @RequestMapping("selectAll")
    public R selectAll(){
        return songService.selectAll();
    }
}
